﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Pipes.Queries.Model.Query
{
  public class Constant : IExpression
  {
    private ConstantType _value;

    public bool Deterministic 
    { 
      get 
      { 
        switch (Value)
        {
          case ConstantType.sysdate:
            return false;
          default:
            return true;
        }
      } 
    }
    public MetaData.GeneralDataType InferredType { get; set; }
    public ConstantType Value 
    { 
      get 
      {
        return _value;
      }
      set
      {
        _value = value;
        switch (value)
        {
          case ConstantType.sysdate:
            this.InferredType = MetaData.GeneralDataType.date;
            break;
          default:
            this.InferredType = MetaData.GeneralDataType.unknown;
            break;
        }
      }
    }

    public Constant() {}
    public Constant(ConstantType value)
    {
      this.Value = value;
    }

    public void Visit(Parser.IQueryVisitor visitor)
    {
      visitor.Visit(this);
    }

    public object Evaluate()
    {
      switch (_value)
      {
        case ConstantType.@null:
          return DBNull.Value;
        default:
          throw new NotImplementedException();
      }
    }
  }
}
